package com.huatek.authority.service;

import java.util.List;

import org.apache.log4j.Logger;

import com.huatek.authority.entity.EfwTargetFieldMap;
import com.huatek.base.entity.BaseEntity;
import com.huatek.base.service.BaseServiceImpl;
import com.huatek.framework.entity.FwDuty;
import com.huatek.framework.tag.CommonBean;
import com.huatek.framework.tag.CutPageBean;
import com.huatek.framework.tag.QueryPageBean;
import com.huatek.framework.util.CommonUtil;

public class EfwTargetFieldServiceImpl  extends BaseServiceImpl implements  EfwTargetFieldService{
	/**
	 * 日志常量.
	 * **/
	private static final Logger LOGGER = Logger
			.getLogger(EfwDataRoleServiceImpl.class);

	/**
	 * 根据参数查询分页数据.
	 *
	 * @param pageBean
	 *            分页对象
	 * @param paramterList
	 *            参数列表
	 * @return 分页结果对象
	 */
	@SuppressWarnings("unchecked")
	public CutPageBean getPageBean(final CutPageBean pageBean,
			final List<CommonBean> paramterList) {
		String totalRowsHsql = " select count(distinct t) from EfwTargetFieldMap t";
		String resultSql = "select distinct t from EfwTargetFieldMap t ";
		return QueryPageBean.getQueryPageBean(hibernateTemplate, totalRowsHsql,
				resultSql, "order by t.id desc", pageBean, paramterList);
	}

	@Override
	public boolean saveOrUpdateEfwTargetField(EfwTargetFieldMap targetField) {

		// 如果名称重复
		if (isDuplicate("from EfwTargetFieldMap t where t.mapName=?",
				new Object[] { targetField.getMapName() }, targetField.getId())) {
			return false;
		}
		if (targetField.isNew()) {
			save(targetField);
		} else {
			merge(targetField);
		}
		return true;
	}

	@Override
	public EfwTargetFieldMap getObjectById(Long id) {
			return (EfwTargetFieldMap)hibernateTemplate.get(EfwTargetFieldMap.class, id);

	}
	@SuppressWarnings("unchecked")
	public List<EfwTargetFieldMap> findDatasByIds(Long[] ids) {
		String param = CommonUtil.getIdSQLParam(ids);
		if (param != null) {
			return (List<EfwTargetFieldMap> )hibernateTemplate.find("from EfwTargetFieldMap"+ " t where t.id in (" + param + ")", ids);
		}
		return null;
	}

}
